import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsEnum, IsNotEmpty, IsOptional, IsString, IsUUID } from 'class-validator';
import { ProjectMemberRole, UserStatus } from '../../../types/enums';
import { User } from '../../../entities/user.entity';

export class AddProjectMemberDto {
  @ApiProperty({
    description: '用户ID',
    example: '123e4567-e89b-12d3-a456-426614174000',
  })
  @IsNotEmpty({ message: '用户ID不能为空' })
  @IsUUID('4', { message: '用户ID必须是有效的UUID' })
  userId: string;

  @ApiPropertyOptional({
    description: '成员角色',
    enum: ProjectMemberRole,
    default: ProjectMemberRole.MEMBER,
    example: ProjectMemberRole.MEMBER,
  })
  @IsOptional()
  @IsEnum(ProjectMemberRole, { message: '成员角色无效' })
  role?: ProjectMemberRole = ProjectMemberRole.MEMBER;
}

export class UpdateProjectMemberDto {
  @ApiProperty({
    description: '成员角色',
    enum: ProjectMemberRole,
    example: ProjectMemberRole.LEADER,
  })
  @IsNotEmpty({ message: '成员角色不能为空' })
  @IsEnum(ProjectMemberRole, { message: '成员角色无效' })
  role: ProjectMemberRole;

  @ApiPropertyOptional({
    description: '成员状态',
    enum: UserStatus,
    example: UserStatus.ACTIVE,
  })
  @IsOptional()
  @IsEnum(UserStatus, { message: '成员状态无效' })
  status?: UserStatus;
}

export class ProjectMemberResponseDto {
  @ApiProperty({
    description: 'ID',
    example: '123e4567-e89b-12d3-a456-426614174000',
  })
  id: string;

  @ApiProperty({
    description: '项目ID',
    example: '123e4567-e89b-12d3-a456-426614174000',
  })
  projectId: string;

  @ApiProperty({
    description: '用户ID',
    example: '123e4567-e89b-12d3-a456-426614174000',
  })
  userId: string;

  @ApiProperty({
    description: '用户信息',
    type: 'object',
    properties: {
      id: { type: 'string' },
      username: { type: 'string' },
      email: { type: 'string' },
      fullName: { type: 'string' },
      avatar: { type: 'string' }
    }
  })
  user: Partial<User>;

  @ApiProperty({
    description: '成员角色',
    enum: ProjectMemberRole,
    example: ProjectMemberRole.MEMBER,
  })
  role: ProjectMemberRole;

  @ApiProperty({
    description: '加入时间',
    example: '2023-01-01T12:00:00Z',
  })
  joinedAt: Date;

  @ApiProperty({
    description: '成员状态',
    enum: UserStatus,
    example: UserStatus.ACTIVE,
  })
  status: UserStatus;

  @ApiProperty({
    description: '创建时间',
    example: '2023-01-01T12:00:00Z',
  })
  createdAt: Date;

  @ApiProperty({
    description: '更新时间',
    example: '2023-01-01T12:00:00Z',
  })
  updatedAt: Date;
} 